home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
WPJV1N5.ZIP
/
HELLO.ZIP
/
HELLO.C
next >
Wrap
C/C++ Source or Header
|
1993-05-02
|
17KB
|
576 lines
/*============================================================================
Hello - Windows Programmer's Journal Volume 1 Number 5
File : Hello.C
Prototype :
Call :
Library :
Example :
24 April 1993 - dlcampbell
1993 Dave Campbell WynApse
----------------------------------------------------------------------------*/
#include <windows.h>
#include "hello.h"
#include <string.h>
char szAppName[] = "Hello";
HANDLE hInst;
HWND hWndMain;
int InitSettings;
static HMENU hMainMenu, hAlternateMenu;
static char szFileName[128];
static char szFileSpec[16];
static char szDefExt[5];
static WORD wFileAttr;
OFSTRUCT of;
LPOFSTRUCT pof;
/*----------------------------------------------------------------------------
Function Prototypes
----------------------------------------------------------------------------*/
BOOL FAR PASCAL AboutDlgProc(HWND, WORD, WORD, LONG);
BOOL FAR PASCAL HelloDlgProc(HWND, WORD, WORD, LONG);
long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
BOOL InitInstance(HANDLE);
int DoFileOpenDlg(HANDLE, HANDLE, POFSTRUCT);
BOOL FAR PASCAL FileOpenDlgProc(HWND, WORD, WORD, LONG);
LPSTR lstrchr (LPSTR str, char ch);
/* The main procedure. This is called by Windows when your program is run. */
/* hInstance is the handle for the current instance of the program */
/* hPrevInst is the handle for the last instance of the program to run */
/* CmdLine is a pointer to a string of whatever command line params came in*/
/* nCmd is the specifies the applications appearance. */
int FAR PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInst, LPSTR CmdLine,
int nCmd)
{
MSG msg; /* Message */
HWND hWnd; /* Our Window Handle */
HMENU hMenu;
if (!hPrevInst) /* If no instance already exists, */
{
if (!InitInstance(hInstance)) /* try initializing instance */
return FALSE; /* No dice, it failed */
}
hInst = hInstance;
hWndMain = CreateWindow(szAppName, /* Window Class */
"Hello World Program", /* Window caption */
WS_OVERLAPPEDWINDOW, /* Overlapped style */
CW_USEDEFAULT, /* Use defaults for the */
CW_USEDEFAULT, /* X & Y Positions and */
CW_USEDEFAULT, /* X & Y sizes */
CW_USEDEFAULT,
NULL, /* Parent Window */
NULL,
hInstance, /* Instance */
NULL); /* Creation Params */
if (hWndMain == NULL)
return 0;
hMenu = GetSystemMenu(hWndMain, FALSE);
hAlternateMenu = LoadMenu(hInstance, "Hello2");
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hMenu, MF_STRING, IDM_HELPABOUT, "About...");
AppendMenu(hMenu, MF_STRING, IDM_SETUP, "Setup...");
ShowWindow(hWndMain, nCmd);
UpdateWindow(hWndMain);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
} /* int FAR PASCAL WinMain */
BOOL InitInstance (HANDLE hInstance)
{
WNDCLASS wc; /* Window class structure */
wc.lpszMenuName = szAppName;
wc.lpszClassName = szAppName;
wc.hbrBackground = GetStockObject(WHITE_BRUSH); /* White bkgrnd */
wc.hInstance = hInstance;
wc.style = CS_VREDRAW | CS_HREDRAW;
wc.lpfnWndProc = WndProc; /* Name of proc to handle window */
wc.hCursor = LoadCursor(NULL, IDC_ARROW); /* Arrow Cursor */
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* Generic Icon */
wc.cbClsExtra = 0; /* no extras */
wc.cbWndExtra = 0; /* No Extras */
return (RegisterClass(&wc)); /* Let's register that class */
} /* BOOL InitInstance */
/* This is our main windows procedure. It receives messages in message, then,
depending on what the message is, we react accordingly
*/
long FAR PASCAL WndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
HMENU hMenu;
static FARPROC lpfnHelloDlgProc, lpfnAboutDlgProc;
char OutMsg[25];
lstrcpy(OutMsg, "");
switch (message)
{
case WM_CREATE :
hMainMenu = GetMenu(hWnd);
InitSettings = GetPrivateProfileInt("Hello", "Setup", 1, "Hello.ini");
InitSettings = InitSettings ? IDM_HELLO : IDM_GOODBYE;
hdc = GetDC(hWnd);
InvalidateRect(hWnd, NULL, TRUE);
ReleaseDC(hWnd, hdc);
/*----------------------------------------------------------------------------
fall through to WM_PAINT...
----------------------------------------------------------------------------*/
case WM_PAINT :
hdc = BeginPaint(hWnd,&ps); /* returns pointer to hdc */
GetClientRect(hWnd, &rect);
/*
-1 tells the DrawText function to calculate length of string based on
NULL-termination
*/
DrawText(hdc, (InitSettings == IDM_HELLO) ? "Hello Windows!" : "Goodbye Windows!", -1,
&rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint(hWnd,&ps);
return 0;
case WM_SYSCOMMAND :
switch (wParam)
{
case IDM_SETUP :
lpfnHelloDlgProc = MakeProcInstance(HelloDlgProc, hInst);
DialogBox(hInst, "Hello", hWnd, lpfnHelloDlgProc);
FreeProcInstance(lpfnHelloDlgProc);
return 0;
case IDM_HELPABOUT :
lpfnAboutDlgProc = MakeProcInstance(AboutDlgProc, hInst);
DialogBox(hInst, "About", hWnd, lpfnAboutDlgProc);
FreeProcInstance(lpfnAboutDlgProc);
return 0;
}
break;
case WM_COMMAND :
hMenu = GetMenu(hWnd);
switch (wParam)
{
case IDM_FILENEW :
lstrcpy(OutMsg, "IDM_FILENEW");
break;
case IDM_FILEOPEN :
if (DoFileOpenDlg(hInst, hWnd, &of))
lstrcpy(OutMsg, (char far *)pof->szPathName);
break;
case IDM_FILESAVE :
lstrcpy(OutMsg, "IDM_FILESAVE");
break;
case IDM_FILESAVEAS :
lstrcpy(OutMsg, "IDM_FILESAVEAS");
break;
case IDM_FILEPRINT :
lstrcpy(OutMsg, "IDM_FILEPRINT");
break;
case IDM_FILEPRINTPREV :
lstrcpy(OutMsg, "IDM_FILEPRINTPREV");
break;
case IDM_FILEPRINTSETUP :
lstrcpy(OutMsg, "IDM_FILEPRINTSETUP");
break;
case IDM_FILEEXIT :
lstrcpy(OutMsg, "IDM_FILEEXIT");
break;
case IDM_EDITUNDO :
lstrcpy(OutMsg, "IDM_EDITUNDO");
break;
case IDM_EDITREPEAT :
lstrcpy(OutMsg, "IDM_EDITREPEAT");
break;
case IDM_EDITCUT :
lstrcpy(OutMsg, "IDM_EDITCUT");
break;
case IDM_EDITCOPY :
lstrcpy(OutMsg, "IDM_EDITCOPY");
break;
case IDM_EDITPASTE :
lstrcpy(OutMsg, "IDM_EDITPASTE");
break;
case IDM_EDITCLEAR :
lstrcpy(OutMsg, "IDM_EDITCLEAR");
break;
case IDM_EDITPAST :
lstrcpy(OutMsg, "IDM_EDITPAST");
break;
case IDM_SAMPLEDLG :
lstrcpy(OutMsg, "IDM_SAMPLEDLG");
break;
case IDM_HELPINDX :
lstrcpy(OutMsg, "IDM_HELPINDX");
break;
case IDM_HELPKBD :
lstrcpy(OutMsg, "IDM_HELPKBD");
break;
case IDM_HELPCMDS :
lstrcpy(OutMsg, "IDM_HELPCMDS");
break;
case IDM_HELPPROCS :
lstrcpy(OutMsg, "IDM_HELPPROCS");
break;
case IDM_HELPUSING :
lstrcpy(OutMsg, "IDM_HELPUSING");
break;
case IDM_HELPABOUT :
lpfnAboutDlgProc = MakeProcInstance(AboutDlgProc, hInst)